package com.qkbb.admin.kuibu.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.qkbb.admin.kuibu.R;
import com.qkbb.admin.kuibu.qkbb.JavaBean.FriendList;
import com.qkbb.admin.kuibu.qkbb.funcation.Friends;
import com.qkbb.admin.kuibu.qkbb.funcation.ImageDownloadSDCardCacheHelper;
import com.qkbb.admin.kuibu.qkbb.funcation.OSShelp;

import java.util.List;

/**
 * Created by admin on 2016/1/27.
 */
public class FriendListAdapter extends BaseAdapter {
   List<Friends> list;
    Context context;

    public FriendListAdapter(List<Friends> list,Context context) {
        this.context=context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
            ViewHold viewHold;
        if (convertView==null){
            convertView= LayoutInflater.from(context).inflate(R.layout.friend_item,null);
            viewHold=new ViewHold();
            viewHold.imageView= (ImageView) convertView.findViewById(R.id.friend_item_image);
            viewHold.textView= (TextView) convertView.findViewById(R.id.friend_item_name);
            convertView.setTag(viewHold);
        }else{
            viewHold= (ViewHold) convertView.getTag();
        }
//        viewHold.imageView.setImageResource(list.get(position).getImage());
        viewHold.textView.setText(list.get(position).getNickname());
        ImageDownloadSDCardCacheHelper imageDownloadSDCardCacheHelper=new ImageDownloadSDCardCacheHelper();
        Friends friendList=list.get(position);
        String url=new OSShelp(context).getBitmap(friendList.getPhoto());
        imageDownloadSDCardCacheHelper.myDownloadImageSDCardCache(context,url,viewHold.imageView,friendList.getPhoto(),1);
        return convertView;
    }
    class ViewHold{
        private ImageView imageView;
        private TextView textView;
    }

}
